﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Basic.第二章.SelfConfig
{
    public class SelfConfigurationSection
    {
    }
    public class ItemsSection : ConfigurationSection
    {
        [ConfigurationProperty("", IsDefaultCollection = true)]
        public ItemElementCollection Items => (ItemElementCollection)base[""];
    }

    public class ItemElementCollection : ConfigurationElementCollection
    {
        private const string ElmentName = "item";
        protected override ConfigurationElement CreateNewElement()
        {
            return new ItemElement();
        }
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((ItemElement)element).Source;
        }

        public override ConfigurationElementCollectionType CollectionType => ConfigurationElementCollectionType.BasicMap;

        protected override string ElementName => ElmentName;
    }

    public class ItemElement : ConfigurationElement
    {
        [ConfigurationProperty("source", IsRequired = true)]
        public string Source
        {
            get { return (string)base["source"]; }
            set { base["source"] = value; }
        }

        [ConfigurationProperty("target", IsRequired = true)]
        public string Target
        {
            get { return (string)base["target"]; }
            set { base["target"] = value; }
        }
    }
}
